package com.xlx.users.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xlx.common.utils.JsonResult;
import com.xlx.users.entity.dto.LoginDTO;
import com.xlx.users.entity.pojo.ThFollow;
import com.xlx.users.entity.pojo.ThUsers;
import com.xlx.users.service.ThUsersService;
import kotlin.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author xieluxing
 * @since 2023-01-29
 */
@RestController
@RequestMapping("/users")
@Slf4j
public class ThUsersController {
    @Autowired
    private ThUsersService thUsersService;

    // 发短信验证码
    @PostMapping("/sendMessage")
    private JsonResult successMsg(@RequestBody LoginDTO loginDTO) {
        return thUsersService.successMsg(loginDTO);
    }

    // 会员登录
    @PostMapping("/login")
    private JsonResult login(@RequestBody LoginDTO loginDTO) {
        return thUsersService.usersLogin(loginDTO);
    }

    // 完善个人信息
    @PutMapping("/info")
    public JsonResult updateUsers(@RequestBody ThUsers thUsers) {
        return thUsersService.updateUsers(thUsers);
    }

    // 添加关注
    @PostMapping("/like")
    public JsonResult addLike(@RequestBody ThFollow thFollow) {
        return thUsersService.addLike(thFollow);
    }

    // 取消关注
    @DeleteMapping("/like")
    public JsonResult deleteLike(@RequestParam("followId") String followId) {
        return thUsersService.deleteLike(followId);
    }

    // 关注页面分页查询
    @GetMapping("like")
    public JsonResult findSearchAll(@RequestParam("name") String name,
                                    @RequestParam("page") Integer page,
                                    @RequestParam("size") Integer size,
                                    @RequestParam("type") Integer type
    ) {
        return thUsersService.findSearchAll(name, page,size,type);
    }

    // 首页推荐
    @GetMapping("/recommendation")
    public JsonResult recommendation() {
        return thUsersService.recommendation();
    }
}
